/*
 * ConstantGenerator.java
 *
 * Created on Piatok, 2007, november 2, 19:30
 *
 */

package logic.distributions;

import java.util.Vector;

/**
 * "Generator" konstantnej hodnoty
 * Parameter 0 -> Double, zadava sa ako String, rozsah (0,nekonecno)
 *
 * @author alvin
 */
public class ConstantGenerator extends AbstractGenerator {
    private double constant = 0;
    
    
    public void initValues() {
        try {
            setParameter(0, "10");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public String checkParameter(int index, Object value) {
        if (!(value instanceof String))
            return "Bad type";
        
        String s = (String)value;
        
        try {
            double d = Double.parseDouble(s);
            if (d < 0.0)
                return "Value must by > 0.0";
        
        }
        catch (NumberFormatException e) {
            return "Not valid float value " + s;
        }
        
        return null;
    }

    protected Vector<String> generateParameterNames() {
        Vector<String> result = new Vector<String>(1);
        result.add("Constant");
        return result;
    }

    public void initGenerator(String generatorName) {
        constant = Double.parseDouble((String)getParameter(0));
    }

    public boolean isDiscreteGenerator() {
        return true;
    }

    public long getDiscreteValue() {
        return Math.round(constant);
    }

    public double getContinuousValue() {
        return constant;
    }

    public String getTypeString() {
        return "ConstantGenerator";
    }
    
}
